/*获得当前项目名*/
function getRootPath(){
		//获取当前网址，
		var curWwwPath=window.document.location.href;
		//获取主机地址之后的目录
		var pathName=window.document.location.pathname;
		var pos=curWwwPath.indexOf(pathName);
		//获取主机地址，
		var localhostPaht=curWwwPath.substring(0,pos);
		//获取带"/"的项目名，
		var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
		return(projectName);
}
//打开一个登录框
function openlogin1(){
	var html = 
		`<div class="login_box">	
			<div class="login_form">
				<div class="login_title">
					登录
				</div>
				<div id="formdiv">
					
					<div class="form_text_ipt">
						<input name="username" id="username" type="text" placeholder="用户名">
					</div>
					<div class="ececk_warning"><span>用户名不能为空</span></div>
					<div class="form_text_ipt">
						<input name="password" id="password" type="password" placeholder="密码">
					</div>
					<div class="ececk_warning"><span>密码不能为空</span></div>
					<div class="form_check_ipt">
						<div class="left check_left">
							<label><input name="" type="checkbox"> 下次自动登录</label>
						</div>
						<div class="right check_right">
							<a href="#">忘记密码</a>
						</div>
					</div>
					<div class="form_btn">
						<button type="button" id="denglu1">登录</button>
					</div>
					<div class="form_reg_btn">
						<span>还没有帐号？</span><a href="`+getRootPath()+"/login"+`">马上注册</a>
					</div>
				</div>
			</div>
		</div>`
			layer.open({
				type:1,
				content:html,
				title:false,
				shadeClose:true,
				scrollbar:false
				})
}
//登录
$("body").on('click', '#denglu1', function (){
	var username = $("#username").val();
	var password = $("#password").val();
	
	nologinislogin1(username,password);
})

//登出
function logout(){
	$.ajax({
		url:getRootPath()+'/admin/logout1',
		method:'get',
		async:false,
		dataType:'json',
		success:function (resultdata){
			if(resultdata.status == 2000){
				window.location.reload();
			}
		},
		error:function (){
			alert("系统出错");
		}
	});
}

function nologinislogin1(username,password){
	
	
	if((username != null || username != '') && (password != null || password != '')){
		$.ajax({
			url : getRootPath()+'/checkLogin',
			type : 'post',
			data :{
				username:username,
				password:password
			},
			async :false,
			datatype:'json',
			success : function(resultdata) {
				var status = resultdata.status ;
				var message = resultdata.message;
				if(status == 200){
					layer.close(layer.index);
					window.location.reload();
				}else{
					alert(message);
				}
			},
			error : function() {
				alert("系统出错");
			}
		})
	}else{
		alert("请输入账号和密码！！");
	}
	
}

